package com.qf.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.constans.ResultCode;
import com.qf.exceptions.AddDataException;
import com.qf.mapper.AuthorMapper;
import com.qf.pojo.Author;
import com.qf.service.AuthorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class AuthorServiceImpl implements AuthorService {
    private AuthorMapper authorMapper;

    @Autowired
    public void setAuthorMapper(AuthorMapper authorMapper) {
        this.authorMapper = authorMapper;
    }

    @Override
    public void addAuthor(Author author) {
        if (author == null || author == null) {
            throw new AddDataException("作者姓名不能为空", ResultCode.WRITER_NAME_IS_NULL);
        }
        authorMapper.addAuthor(author);

    }

    @Override
    public PageInfo<Author> getAllAuthor(int page, int limit) {
        PageHelper.startPage(page, limit);
        List<Author> authorList = authorMapper.getAllAuthor();
        PageInfo<Author> pageInfo = new PageInfo<>(authorList);
        return pageInfo;
    }
}